package com.weishu.house.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.weishu.common.core.domain.R;
import com.weishu.common.core.web.controller.BaseController;
import com.weishu.common.core.web.page.TableDataInfo;
import com.weishu.house.entity.Business;
import com.weishu.house.entity.SysDept;
import com.weishu.house.entity.SysRegion;
import com.weishu.house.entity.SysUser;
import com.weishu.house.service.IBusinessService;
import com.weishu.house.service.ISysDeptService;
import com.weishu.house.service.ISysRegionService;
import com.weishu.house.service.ISysUserService;
import org.hamcrest.core.Is;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商户表 前端控制器
 * </p>
 *
 * @author gao
 * @since 2021-05-25
 */
@RestController
@RequestMapping("/business")
public class BusinessController extends BaseController {

    @Autowired
    private IBusinessService iBusinessService;

    @Autowired
    private ISysUserService iSysUserService;

    @Autowired
    private ISysDeptService iSysDeptService;

    @Autowired
    private ISysRegionService iSysRegionService;
    @GetMapping("list")
    private TableDataInfo list(){
        startPage();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("id");
        List<Business> lists = iBusinessService.list(queryWrapper);


        for (Business list :lists){
            Integer userId = list.getUserId();
            SysUser byId =null;
            if(userId!=null){

                byId = iSysUserService.getById(userId);
            }
            if(!byId.getUsername().equals(null)){

                list.setUsername(byId.getUsername());
            }

        }
        return getDataTable(lists);
    }
    @PostMapping("listByid")
    private R<?> listByid(@RequestBody Integer ids){
        Business business = iBusinessService.getById(ids);
        SysUser user = iSysUserService.getById(business.getUserId());
        business.setUsername(user.getUsername());
        return R.ok(business);
    }

}
